package com.fr.lintcode;

import org.junit.Test;

/**
*作者：furong
*日期：2016年12月28日
*时间：下午7:15:34
*/
public class Q74 {
    /**
     * @param n: An integers.
     * @return: An integer which is the first bad version.
     */
    public int findFirstBadVersion(int n) {
        long m = 1;
        long point = -1;
        long error = -1;
        long nn = n;
        while (m <= nn) {
            point = (m + nn) / 2;
            if (!isBadVersion((int)point)) {
                m = point + 1;
            } else {
                error = point;
                nn = point - 1;
            }
        }
        return (int)error;
    }

    private boolean isBadVersion(int point) {
        if (point == 2147483647) {
            return true;
        }
        return false;
    }

    @Test
    public void testA() {
        System.out.println(findFirstBadVersion(2147483647));
    }

}
